home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d18 / opbonus.arc / ALARM.ARC / ALARMI.ASM < prev    next >
Assembly Source File  |  1991-03-20  |  4KB  |  134 lines

  1. ;ALARMI.ASM - Int 1Ch handler and supporting routines for ALARM.PAS
  2. ;by TurboPower Software
  3. CODE   SEGMENT BYTE PUBLIC
  4.        ASSUME  CS:CODE,DS:NOTHING
  5.        PUBLIC  EnableTasks,DisableTasks,Int1CHandler,AlarmCSData
  6.        EXTRN   SetPopTicker:Far
  7.  
  8. ;Structure of a pointer
  9. Pointer STRUC
  10.         Ofst    DW      0
  11.         Segm    DW      0
  12. Pointer ENDS
  13.  
  14. ;the following label is used by the pascal code to locate the CS
  15. ;relative data
  16. AlarmCSData:
  17. TickCountToPop   dd 0                  ;the tick count to popup on
  18. TickDataPtr      Pointer <>            ;pointer to userdata of IFCRecord
  19. TasksEnabled     db 0                  ;enabled flag
  20.  
  21. Save1C           Pointer <>            ;save original int 1Ch vector
  22. InInt1C          db 0
  23.  
  24. SaveAllRegs      MACRO
  25.        PUSH      BP
  26.        PUSH      AX
  27.        PUSH      BX
  28.        PUSH      CX
  29.        PUSH      DX
  30.        PUSH      DS
  31.        PUSH      ES
  32.        PUSH      SI
  33.        PUSH      DI
  34.        ENDM
  35.  
  36. RestoreAllRegs   MACRO
  37.        POP       DI
  38.        POP       SI
  39.        POP       ES
  40.        POP       DS
  41.        POP       DX
  42.        POP       CX
  43.        POP       BX
  44.        POP       AX
  45.        POP       BP
  46.        ENDM
  47.  
  48. Int1CHandler     PROC FAR
  49.         ;first, emulate int 1C to call original vector
  50.         PUSHF
  51.         CALL     DWORD PTR Save1C
  52.  
  53.         STI                            ; enable interrupts
  54.         ;save regs we will use (whether alarm time or not)
  55.         PUSH     DS
  56.         PUSH     BX
  57.         PUSH     AX
  58.  
  59.         MOV      BX,40h
  60.         MOV      DS,BX
  61.         MOV      BX,6Ch                ;make DS:BX point to BIOS tick count
  62.         MOV      AX,word ptr CS:TickCountToPop
  63.         ;compare low words of current tick count to alarm tick count
  64.         CMP      AX,[BX]
  65.         JNE      Int1CExit             ;if not equal, then exit
  66.         INC      BX
  67.         INC      BX
  68.         MOV      AX,word ptr CS:TickCountToPop+2
  69.         ;compare high words
  70.         CMP      AX,[BX]
  71.         JNE      Int1CExit             ;if not equal, then exit
  72.  
  73.         ;if we make it here then it is time to popup alarm
  74.         SaveAllRegs
  75.         XOR      AX,AX
  76.         LES      DI, TickDataPtr       ; point to ThisIFC.UserData
  77.         CLD                            ; clear direction flag
  78.         STOSW                          ; put a zero longint in it
  79.         STOSW
  80.         MOV      AX, 07FFFh
  81.         PUSH     AX                    ; push the ticker count
  82.         CALL     SetPopTicker          ;equivelent to SetPopTicker($7FFF);
  83.         RestoreAllRegs
  84.  
  85. Int1CExit:
  86.         ;restore the regs that are always used
  87.         POP      AX
  88.         POP      BX
  89.         POP      DS
  90.         IRET
  91. Int1CHandler     ENDP
  92.  
  93. ;save original int 1Ch vector and install new one
  94. EnableTasks      PROC FAR
  95.          TEST    CS:TasksEnabled,1     ;check enabled flag
  96.          JNZ     ET_Exit               ;if already enabled, then exit
  97.          PUSH    DS                    ;save DS
  98.          MOV     AX,CS                 ;make DS = CS
  99.          MOV     DS,AX
  100.  
  101.          MOV     AX,351Ch
  102.          INT     21h                   ;get current int 1Ch
  103.          MOV     Save1C.Ofst,BX        ;save for later
  104.          MOV     BX,ES
  105.          MOV     Save1C.Segm,BX
  106.  
  107.          MOV     DX,OFFSET Int1CHandler
  108.          MOV     AX,251Ch
  109.          INT     21h                   ;set up our int 1Ch handler
  110.  
  111.          MOV     CS:TasksEnabled,1     ;set enabled flag
  112.          POP     DS                    ;restore DS
  113. ET_Exit:
  114.          RET
  115. EnableTasks      ENDP
  116.  
  117. ;restore original int 1Ch handler
  118. DisableTasks     PROC FAR
  119.          TEST    CS:TasksEnabled,1     ;see if tasks are enabled
  120.          JZ      DT_Exit               ;if not then exit
  121.          PUSH    DS
  122.          MOV     AX,CS:Save1C.Segm
  123.          MOV     DX,CS:Save1C.Ofst
  124.          MOV     DS,AX
  125.          MOV     AX,251Ch              ;put back original int 1Ch handler
  126.          INT     21h
  127.          MOV     CS:TasksEnabled,0     ;clear enabled flag
  128.          POP     DS
  129. DT_Exit:
  130.          RET
  131. DisableTasks     ENDP
  132. CODE    ENDS
  133.         END
  134.